Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / core / ui / src / commonMain / kotlin / org / meshtastic / core / ui / component / ScrollExtensions.kt

Displaying Raw • Download

core/ui/src/commonMain/kotlin/org/meshtastic/core/ui/component/ScrollExtensions.kt 520fa717a938fd84682403b41f57d9f7e1ef49ef (520fa717) Text, 2.68 KB

T8b949e/*
* Copyright (c) 2025-2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.ui.component

Tff7b72import T7ee787androidx.compose.foundation.lazy.LazyListState
Tff7b72import T7ee787kotlinx.coroutines.CoroutineScope
Tff7b72import T7ee787kotlinx.coroutines.launch

Tff7b72private Tff7b72const Tff7b72val Te6edf3SCROLL_TO_TOP_INDEX Tff7b72= T79c0ff0
Tff7b72private Tff7b72const Tff7b72val Te6edf3FAST_SCROLL_THRESHOLD Tff7b72= T79c0ff1T79c0ff0

T8b949e/**
* Executes the smart scroll-to-top policy.
*
* Policy:
* - If the first visible item is already at index 0, do nothing.
* - Otherwise, smoothly animate the list back to the first item.
*/
Tff7b72fun Te6edf3LazyListStateTb4b4b4.Td2a8ffsmartScrollToTopTb4b4b4(Te6edf3coroutineScopeTb4b4b4: Te6edf3CoroutineScopeTb4b4b4) Tb4b4b4{
Te6edf3smartScrollToIndexTb4b4b4(Te6edf3coroutineScope Tff7b72= Te6edf3coroutineScopeTb4b4b4, Te6edf3targetIndex Tff7b72= Te6edf3SCROLL_TO_TOP_INDEXTb4b4b4)
Tb4b4b4}

T8b949e/**
* Scrolls to the [targetIndex] while applying the same fast-scroll optimisation used by [smartScrollToTop].
*
* If the destination is far away, the list first jumps closer to the goal (within [FAST_SCROLL_THRESHOLD] items) to
* avoid long smooth animations and then animates the final segment.
*
* @param coroutineScope Scope used to perform the scroll operations.
* @param targetIndex Absolute index that should end up at the top of the viewport.
*/
Tff7b72fun Te6edf3LazyListStateTb4b4b4.Td2a8ffsmartScrollToIndexTb4b4b4(Te6edf3coroutineScopeTb4b4b4: Te6edf3CoroutineScopeTb4b4b4, Te6edf3targetIndexTb4b4b4: Tffa657IntTb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3targetIndex Tff7b72< T79c0ff0 Tff7b72|Tff7b72| Te6edf3firstVisibleItemIndex Tff7b72=Tff7b72= Te6edf3targetIndexTb4b4b4) Tb4b4b4{
Tff7b72return
Tb4b4b4}
Te6edf3coroutineScopeTb4b4b4.Te6edf3launch Tb4b4b4{
Tff7b72val Te6edf3totalItems Tff7b72= Te6edf3layoutInfoTb4b4b4.Te6edf3totalItemsCount
Tff7b72if Tb4b4b4(Te6edf3totalItems Tff7b72=Tff7b72= T79c0ff0Tb4b4b4) Tb4b4b4{
Tff7b72returnTf0883e@launch
Tb4b4b4}
Tff7b72val Te6edf3clampedTarget Tff7b72= Te6edf3targetIndexTb4b4b4.Te6edf3coerceInTb4b4b4(T79c0ff0Tb4b4b4, Te6edf3totalItems Tff7b72- T79c0ff1Tb4b4b4)
Tff7b72val Te6edf3difference Tff7b72= Te6edf3firstVisibleItemIndex Tff7b72- Te6edf3clampedTarget
Tff7b72val Te6edf3jumpIndex Tff7b72=
Tff7b72when Tb4b4b4{
Te6edf3difference Tff7b72> Te6edf3FAST_SCROLL_THRESHOLD Tff7b72-Tff7b72>
Tb4b4b4(Te6edf3clampedTarget Tff7b72+ Te6edf3FAST_SCROLL_THRESHOLDTb4b4b4)Tb4b4b4.Te6edf3coerceAtMostTb4b4b4(Te6edf3totalItems Tff7b72- T79c0ff1Tb4b4b4)
Te6edf3difference Tff7b72< Tff7b72-Te6edf3FAST_SCROLL_THRESHOLD Tff7b72-Tff7b72> Tb4b4b4(Te6edf3clampedTarget Tff7b72- Te6edf3FAST_SCROLL_THRESHOLDTb4b4b4)Tb4b4b4.Te6edf3coerceAtLeastTb4b4b4(T79c0ff0Tb4b4b4)
Tff7b72else Tff7b72-Tff7b72> Tff7b72null
Tb4b4b4}
Te6edf3jumpIndexTff7b72?.Te6edf3let Tb4b4b4{ Te6edf3scrollToItemTb4b4b4(Tffa657itTb4b4b4) Tb4b4b4}
Te6edf3animateScrollToItemTb4b4b4(Te6edf3index Tff7b72= Te6edf3clampedTargetTb4b4b4)
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.04s